package com.jingbo.servlet;

import com.jingbo.DAO.Record.pecordimpl;
import com.jingbo.entity.Profile;
import com.jingbo.entity.paging;
import com.jingbo.service.record.recordimpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author jiangjingbo
 * @version V1.0
 * @Project java2203
 * @Package com.jingbo.servlet
 * @Description:
 * @Date 2022/5/27 15:28
 */
@WebServlet("/selectAll")
public class selectProfile extends BeanServlet {

    public String selectAll(HttpServletRequest request, HttpServletResponse response) {
        recordimpl recordimpl = new recordimpl(new pecordimpl());
        //获取前端传来的当前页面数据
        String pageIndex = request.getParameter("pageIndex");
        if(pageIndex==null){
            pageIndex="1";
        }
        Integer index = Integer.valueOf(pageIndex);
        paging paging = new paging();
        paging.setPageSize(5);
        Integer countpaging = recordimpl.Countpaging();
        paging.setPageIndex(index);
        //起始行 从第几条开始查询 =( 当前页数-1) *每页显示数据条数
        paging.setStartRows((paging.getPageIndex()-1)*paging.getPageSize());
        //总页数 = 总页数 % 每条显示条数 == 0 ? 总页数/ 每页显示条数 : 总条数/ 每页显示条数+1
        paging.setTotalPages(countpaging%paging.getPageSize()==0 ?countpaging/paging.getPageSize():countpaging/paging.getPageSize()+1);

        List<Profile> list1 = recordimpl.profileall(paging.getStartRows(), paging.getPageSize());
//        getStartRows   getPageSize
        List<Profile> list = recordimpl.selectProfile();
        if(list!=null){
            request.getSession().setAttribute("page",paging);
            request.getSession().setAttribute("list",list1);
            return "redirect:/selectAdd.jsp";
        }else{
            return "redirect:/addrecord.jsp";
        }
    }
}
